#### Uncertainty and Conflict Termination Preferences ####
######### Reproduction materials (Appendix) #############

set.seed(1310)

# load packages
source("code/packages.r")

#list
conflict_list <- c("5665", "18001", "23466", "52835", "76109", "76275", "86568") #Municipalities in Espada de Honor (Matanock2018, Tellez2018)

# load data
load("data/survey_df.RData")
load("data/survey13_df.RData")
polls_df <- readr::read_csv("data/polls.csv")
concessions_tab_df <- readxl::read_xlsx("data/concessions-table.xlsx")
google_df <- readr::read_csv("data/google_search.csv")
wikipedia_df <- readr::read_csv("data/wikipedia_search.csv")
robustness_table_df <- readxl::read_xlsx("data/robustness-table.xlsx")

## -----------------------------------------------------------------
## STA1. Robustness tests (index) ----------------------------------
## -----------------------------------------------------------------

robustness_table_df %>% gt::gt() %>%
  gtExtras::gt_theme_nytimes() %>%
  gtExtras::gt_img_multi_rows(columns = Result, height = 19) %>%
  gt::fmt_markdown(columns = c("Section")) %>%
  gt::tab_style(
    style = list(cell_text(color = "#000", align = "center",v_align = "middle", weight = "bold")),
    locations = cells_column_labels(columns = c(everything())
    )) %>%
  gt::gtsave("figures/supp-table-a1-index.png")

## -----------------------------------------------------------------
## SFA1. Results of opinion polls leading to the plebiscite ----
## -----------------------------------------------------------------

fig_a1 <- polls_df %>% tidyr::pivot_longer(.,c("yes", "no", "dk_nr"), names_to = "option", values_to = "result") %>%
  ggplot(., aes(x=id, y=result, fill=option)) +
  geom_bar(aes(alpha =option), stat = "identity", color = "black", size = 0.05) +
  geom_hline(yintercept=0.5, linetype="dashed", linewidth = 0.3) +
  theme_minimal() +
  scale_x_discrete(breaks = c(1,2,3,4,5,6,7,8,9,10,11,13), 
                   labels = c("Invamer Gallup","Cifras & Conceptos","Datexco","Ipsos NF",
                              "Datexco", "Datexco", "Invamer Gallup", "Cifras & Conceptos",
                              "Datexco", "Cifras & Conceptos", "Ipsos NF", "Election Results"  
                   )) + 
  scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
  scale_fill_manual(values = c("#d3d3d3","#4575b4", "#b44575"), #c("#e0ecf4","#9ebcda", "#8856a7"),
                    guide = guide_legend(reverse = TRUE),
                    labels = c("Don't know","No", "Yes")
  ) +
  scale_alpha_manual(values = c(0.2, 0.5, 1),
                     guide = guide_legend(reverse = TRUE),
                     labels = c("Don't know","No", "Yes")
  ) +
  geom_text(aes(label = pollster, y = -0.03), size = 2.6) +
  geom_text(aes(label = date_verb, y = -0.065), size = 2.8) +
  theme(text = element_text(family = "Roboto Condensed"),
        legend.position = "bottom",
        legend.title = element_blank(),
        axis.title.x=element_blank()) +
  labs(y = "")

ggsave(fig_a1, file = "figures/suppfig-a1-polls.png", width = 4, height = 2,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)

## -----------------------------------------------------------------
## SFA2. Salience Google and Wikipedia searches --------------------
## -----------------------------------------------------------------

google_plot <- ggplot(google_df, aes(x=lubridate::mdy(day), y=interest)) +
  geom_line() +
  theme_minimal() +
  theme(text = element_text(family = "Roboto Condensed"),title = element_text(color = "darkblue")) +
  geom_vline(xintercept=lubridate::mdy("10/02/2016"), linetype="longdash", color = "#998ec3", size = 0.5) +
  labs(x="Day",
       y="Interest",
       title = "a) Google",
       subtitle = "Topic: 2016 Colombian peace agreement referendum")

wiki_plot <- ggplot(wikipedia_df, aes(x=lubridate::mdy(date), y=traffic)) +
  geom_line() +
  theme_minimal() +
  theme(text = element_text(family = "Roboto Condensed"),title = element_text(color = "darkblue")) +
  geom_vline(xintercept=lubridate::mdy("10/02/2016"), linetype="longdash", color = "#998ec3", size = 0.5) +
  labs(x="Day",
       y="PageViews",
       title = "b) Wikipedia",
       subtitle = "Article: 2016 Colombian peace agreement referendum")

fig_a2 <- google_plot + wiki_plot

ggsave(fig_a2, file = "figures/suppfig-a2-salience-plot.png", width = 4, height = 2,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)

## -----------------------------------------------------------------
## SFTA2. Balance table ---------------------------------------------
## -----------------------------------------------------------------

cov_vars <-  tibble::tibble(variables =c("age", "female", "edu", "urban", "estrato", "votesantos", "victim_ruv", "relative_farc_vict", "conflict_zone"),
                            label = c("Age",  "Female", "Years of education", "Urban", "Income level",  "Vote Incumbent (Santos)", "Victim (Unified Victim Registry)",  "Family victimized by FARC", "Conflict-zone"))

survey_df %>%
  dplyr::summarize_at(cov_vars$variables, funs(list(broom::tidy(t.test(. ~ d))))) %>% # sequentially run t-tests across all the covariates in the list_cov (note that you have to change the "treatment")
  purrr::map(1) %>%
  dplyr::bind_rows(.id='variables') %>%  
  dplyr::select(variables, estimate1, estimate2, p.value) %>% 
  dplyr::mutate_if(is.numeric, round, 3) %>%
  dplyr::left_join(cov_vars, .) %>%
  dplyr::select(-variables) %>%
  gt::gt() %>%
  gt::cols_label(label = "",
                 estimate1 = "(Pre-plebiscite = 0)",
                 estimate2 = "(Post-plebiscite = 1)") %>%
  gtExtras::gt_theme_nytimes() %>%
  gt::tab_style(
    style = list(cell_text(color = "#000", align = "center",v_align = "middle", weight = "bold")),
    locations = cells_column_labels(columns = c(everything())
    )) %>%
  gt::gtsave("figures/supp-table-a2-balance-table.png")

## -----------------------------------------------------------------
## SFT3. Multiple bandwidths ---------------------------------------
## -----------------------------------------------------------------

bw_list <- list(
  "Naive" = estimatr::lm_robust(scaled_support_agreement ~ d , data = survey_df[survey_df$bw15 == 1,]),
  "Dem" = estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$bw15 == 1,]),
  "Dem + Conf"= estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$bw15 == 1,]),
  "Naive" = estimatr::lm_robust(neg_farc ~ d , data = survey_df[survey_df$bw15 == 1,]),
  "Dem" = estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$bw15 == 1,]),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$bw15 == 1,]),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ d, data = survey_df[survey_df$bw15 == 1,]),
  "Dem" =  estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$bw15 == 1,]),
  "Dem + Conf" = estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$bw15 == 1,]),
  "Naive" = estimatr::lm_robust(scaled_support_agreement ~ d , data = survey_df[survey_df$bw7 == 1,]),
  "Dem" = estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$bw7 == 1,]),
  "Dem + Conf"= estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$bw7 == 1,]),
  "Naive" = estimatr::lm_robust(neg_farc ~ d , data = survey_df[survey_df$bw7 == 1,]),
  "Dem" = estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$bw7 == 1,]),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$bw7 == 1,]),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ d, data = survey_df[survey_df$bw7 == 1,]),
  "Dem" =  estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$bw7 == 1,]),
  "Dem + Conf" = estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$bw7 == 1,])
)

modelsummary::modelsummary(bw_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Signed agreement" = 3,"Negotiated-end (FARC)" = 3, "Concessions (Composite)" = 3, "Signed agreement" = 3, "Negotiated-end (FARC)" = 3, "Concessions (Composite)" = 3)) %>%
  kableExtra::add_header_above(c(" " = 1, "±15 days" = 9, "±7 days" = 9)) %>%
  kableExtra::row_spec(1,bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(2,bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-a3-multiplebw.png",
                         zoom = 1.8,
                         density = 600)

## -----------------------------------------------------------------
## SFT4-9. Analysis of non-response ---------------------------------
## -----------------------------------------------------------------

# attrition (non-response) ----------------

#farc
att_farc_tab <- table(haven::as_factor(survey_df$colpaz1a), survey_df$d) %>% prop.table(margin = 2) %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Value" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)) %>%
  dplyr::mutate(Pre = paste0(round(Pre*100,2), "\\%"),
                Post = paste0(round(Post*100,2), "\\%"),
                Difference = paste0(round(Difference*100,2), "\\%"))

print(xtable::xtable(att_farc_tab, scientific = F, align = c("l","l", "c", "c", "c"), 
                     caption = "Analysis of nonresponse. Of the following options to solve the conflict with the FARc, which do you think is the best? \\label{tab:att_farc_tab}"), booktabs = TRUE,
      size = "small", caption.placement = "top", table.placement = "t!bh", include.rownames = FALSE,
      sanitize.text.function=function(x){x}, file = "figures/supp-table-a4-att_farc_tab.tex") 

#political participation
att_con1_tab <- table(haven::as_factor(survey_df$colconce4), survey_df$d) %>% prop.table(margin = 2) %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Value" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)) %>%
  dplyr::mutate(Pre = paste0(round(Pre*100,2), "\\%"),
                Post = paste0(round(Post*100,2), "\\%"),
                Difference = paste0(round(Difference*100,2), "\\%"))

print(xtable::xtable(att_con1_tab, scientific = F, align = c("l","l", "c", "c", "c"), 
                     caption = "Analysis of nonresponse. The Colombian government must guarantee that demobilized FARC members can participate in politics. To what extent do you agree or disagree? \\label{tab:att_con1_tab}"), booktabs = TRUE,
      size = "small", caption.placement = "top", table.placement = "t!bh", include.rownames = FALSE,
      sanitize.text.function=function(x){x}, file = "figures/supp-table-a5-att_con1_tab.tex") 

#no jail for rank
att_con2_tab <- table(haven::as_factor(survey_df$colpact1), survey_df$d) %>% prop.table(margin = 2) %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Value" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)) %>%
  dplyr::mutate(Pre = paste0(round(Pre*100,2), "\\%"),
                Post = paste0(round(Post*100,2), "\\%"),
                Difference = paste0(round(Difference*100,2), "\\%"))

print(xtable::xtable(att_con2_tab, scientific = F, align = c("l","l", "c", "c", "c"), 
                     caption = "Analysis of nonresponse. It was agreed that the rank and file membersof the FARC (not commanders) who demobilize will not go to jail. To what extent do you agree or disagree? \\label{tab:att_con2_tab}"), booktabs = TRUE,
      size = "small", caption.placement = "top", table.placement = "t!bh", include.rownames = FALSE,
      sanitize.text.function=function(x){x}, file = "figures/supp-table-a6-att_con2_tab.tex") 

#deprivation of liberty
att_con3_tab <- table(haven::as_factor(survey_df$colpact11a), survey_df$d) %>% prop.table(margin = 2) %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Value" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)) %>%
  dplyr::mutate(Pre = paste0(round(Pre*100,2), "\\%"),
                Post = paste0(round(Post*100,2), "\\%"),
                Difference = paste0(round(Difference*100,2), "\\%"))

print(xtable::xtable(att_con3_tab, scientific = F, align = c("l","l", "c", "c", "c"), 
                     caption = "Analysis of nonresponse. It was agreed that the members of the FARC, who are responsible for atrocious crimes and who confess their crimes, pay between five (5) and eight(8) years of deprivation of liberty. To what extent do you agree or disagree? \\label{tab:att_con3_tab}"), booktabs = TRUE,
      size = "small", caption.placement = "top", table.placement = "t!bh", include.rownames = FALSE,
      sanitize.text.function=function(x){x}, file = "figures/supp-table-a7-att_con3_tab.tex") 

#guaranties for political party
att_con4_tab <- table(haven::as_factor(survey_df$colpact11), survey_df$d) %>% prop.table(margin = 2) %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Value" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)) %>%
  dplyr::mutate(Pre = paste0(round(Pre*100,2), "\\%"),
                Post = paste0(round(Post*100,2), "\\%"),
                Difference = paste0(round(Difference*100,2), "\\%"))

print(xtable::xtable(att_con4_tab, scientific = F, align = c("l","l", "c", "c", "c"), 
                     caption = "Analysis of nonresponse. It was agreed that political parties made up of demobilized ex-combatants of the FARC will have thesame guarantees of security and access to the media that other political parties already have. To what extent do you agree or disagree? \\label{tab:att_con4_tab}"), booktabs = TRUE,
      size = "small", caption.placement = "top", table.placement = "t!bh", include.rownames = FALSE,
      sanitize.text.function=function(x){x}, file = "figures/supp-table-a8-att_con4_tab.tex") 

#territorial concentration
att_con5_tab <- table(haven::as_factor(survey_df$colpact14), survey_df$d) %>% prop.table(margin = 2) %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Value" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)) %>%
  dplyr::mutate(Pre = paste0(round(Pre*100,2), "\\%"),
                Post = paste0(round(Post*100,2), "\\%"),
                Difference = paste0(round(Difference*100,2), "\\%"))

print(xtable::xtable(att_con5_tab, scientific = F, align = c("l","l", "c", "c", "c"), 
                     caption = "Analysis of nonresponse. It was agreed that the members of the FARC willconcentrate in some regionsof the country. To what extent do you agree or disagree? \\label{tab:att_con5_tab}"), booktabs = TRUE,
      size = "small", caption.placement = "top", table.placement = "t!bh", include.rownames = FALSE,
      sanitize.text.function=function(x){x}, file = "figures/supp-table-a9-att_con5_tab.tex") 


## -----------------------------------------------------------------
## SFT9-10. Placebo effects in control group -----------------------
## -----------------------------------------------------------------

#Negiotiated-end placebo
farc_placebo_list <- list(
  "Naive" = estimatr::lm_robust(neg_farc ~ p15 , data = survey_df),
  "Dem" = estimatr::lm_robust(neg_farc ~ p15 + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ p15 + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df),
  "Naive" = estimatr::lm_robust(neg_farc ~ p30 , data = survey_df),
  "Dem" = estimatr::lm_robust(neg_farc ~ p30 + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ p30 + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df),
  "Naive" = estimatr::lm_robust(neg_farc ~ p45 , data = survey_df),
  "Dem" = estimatr::lm_robust(neg_farc ~ p45 + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ p45 + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df)
)

modelsummary::modelsummary(farc_placebo_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Negotiated-end (FARC)" = 9)) %>%
  kableExtra::row_spec(c(1,3,5),bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(c(2,4,6),bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-a10-placebo-negiotiated.png",
                         zoom = 1.8,
                         density = 600)

#Concessions placebo
concessions_placebo_list <- list(
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ p15 , data = survey_df),
  "Dem" = estimatr::lm_robust(conce_agg_scale ~ p15 + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(conce_agg_scale ~ p15 + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ p30 , data = survey_df),
  "Dem" = estimatr::lm_robust(conce_agg_scale ~ p30 + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(conce_agg_scale ~ p30 + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ p45 , data = survey_df),
  "Dem" = estimatr::lm_robust(conce_agg_scale ~ p45 + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(conce_agg_scale ~ p45 + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df)
)

modelsummary::modelsummary(concessions_placebo_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Concessions (Composite)" = 9)) %>%
  kableExtra::row_spec(c(1,3,5),bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(c(2,4,6),bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-a11-placebo-concessions.png",
                         zoom = 1.8,
                         density = 600)

## -----------------------------------------------------------------
## SFA3. Placebo effects in control group --------------------------
## -----------------------------------------------------------------

fig_a3 <- survey_df %>% 
  dplyr::group_by(week = lubridate::week(fecha-3)) %>% mutate(number_of_respondents = n(), 
                                                              neg_farc_week = mean(neg_farc, na.rm=T)) %>%
  dplyr::ungroup() %>%
  dplyr::select(week, fecha, number_of_respondents, neg_farc_week) %>%
  dplyr::distinct() %>%
  dplyr::mutate(week = week - 40) %>%
  ggplot( aes(x = week, y = neg_farc_week, size = number_of_respondents)) +
  geom_point() +
  geom_vline(xintercept=-0.4, linetype="dotted") +
  scale_y_continuous(limits = c(0.3, 1)) +
  theme_minimal() +
  scale_size(guide = NULL) +labs(y = "Proportion of respondents\n",
                                 linetype = "") +
  theme(text = element_text(family = "Roboto Condensed",
                            size = 14),
        legend.position = "bottom",
        axis.title.x=element_blank()) +
  scale_x_continuous(breaks = c(-8, -4, 0, 3), labels = c("(Aug 8-14)\nW-8", "(Sep 5-11)\nW-4", "(Oct 3-9)\nW", "(Oct 24-30)\nW+3")) +
  geom_curve(data = data.frame(x = -0.4,
                               y = 0.3,
                               xend = -3.5,
                               yend = 0.4),
             mapping = aes(x = x,
                           y = y,
                           xend = xend,
                           yend = yend),
             size = 0.5,
             angle = 33L,
             colour = "black",
             curvature = -0.525,
             arrow = structure(list( angle = 30,
                                     length = structure(0.1,
                                                        class = "unit",
                                                        valid.unit = 2L,
                                                        unit = "inches"),
                                     ends = 2L,
                                     type = 2L),
                               class = "arrow"),
             inherit.aes = FALSE,
             show.legend = FALSE) +
  geom_text(data = data.frame(x = -3.5,
                              y = 0.44,
                              label = "Results were released the evening of\nPlebiscite day"),
            mapping = aes(x = x,
                          y = y,
                          label = label),
            size = 3.8,
            angle = 0L,
            lineheight = 1L,
            hjust = 0.5,
            vjust = 0.5,
            colour = "black",
            family = "Roboto Condensed",
            fontface = "plain",
            inherit.aes = FALSE,
            show.legend = FALSE) +
  geom_curve(data = data.frame(x = -5.7,
                               y = 0.76,
                               xend = -4,
                               yend = 0.85),
             mapping = aes(x = x,
                           y = y,
                           xend = xend,
                           yend = yend),
             size = 0.5,
             angle = 80L,
             colour = "black",
             curvature = 0.3,
             arrow = structure(list(angle = -30,
                                     length = structure(0.1,
                                                        class = "unit",
                                                        valid.unit = 2L,
                                                        unit = "inches"),
                                     ends = 2L,
                                     type = 2L),
                               class = "arrow"),
             inherit.aes = FALSE,
             show.legend = FALSE) +
  geom_text(data = data.frame(x = -4,
                              y = 0.90,
                              label = "Government announces that the agreement\nwas reached on Aug 25, 2016"),
            mapping = aes(x = x,
                          y = y,
                          label = label),
            size = 3.8,
            angle = 0L,
            lineheight = 1L,
            hjust = 0.5,
            vjust = 0.5,
            colour = "black",
            family = "Roboto Condensed",
            fontface = "plain",
            inherit.aes = FALSE,
            show.legend = FALSE)

ggsave(fig_a3, file = "figures/suppfig-a3-weekly-trend.png", width = 4, height = 2,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)

## -----------------------------------------------------------------
## SFA4 and STA12. Placebo effects in other survey -----------------
## -----------------------------------------------------------------

# lapop 13 ----------------
summary(mod_farc_lapop13_1 <- estimatr::lm_robust(neg_farc ~ d , data = survey13_df))
summary(mod_farc_lapop13_2 <- estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos, data = survey13_df))
summary(mod_farc_lapop13_3 <- estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey13_df))

fig_sfa4_df <- dplyr::bind_rows(
  mod_farc_lapop13_1 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Naive", model = "Negotiated-end (FARC)"),
  mod_farc_lapop13_2 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Demographic", model = "Negotiated-end (FARC)"),
  mod_farc_lapop13_3 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Demographic + Conflict", model = "Negotiated-end (FARC)")
  ) %>% dplyr::filter(term == "d") %>%
  dplyr::mutate(type = forcats::fct_relevel(type, c("Demographic + Conflict", "Demographic", "Naive")),
                term = dplyr::case_when(term == "d" ~ "Placebo treatment (October 2, 2013)"))

fig_sfa4 <- ggplot(fig_sfa4_df, aes(x = type, y = estimate, color = type, shape = type, fill = type)) +
  geom_point(size = 2) +
  geom_segment(aes(x = type, xend = type, y = conf.low, yend = conf.high), size = 0.5) +
  geom_hline(yintercept = 0, linetype = "longdash", color = "gray60") +
  coord_flip() +
  theme_bw() +
  scale_y_continuous(limits = c(-.15,.3)) +
  scale_color_manual(guide = guide_legend(reverse = TRUE),
                     values = c("#000000", "darkgray", "#0065b8")) +
  scale_fill_manual(guide = guide_legend(reverse = TRUE),
                    values = c("#000000", "darkgray", "#0065b8")) +
  scale_shape_manual(values = c(21, 22, 23),
                     guide = guide_legend(reverse = TRUE)) +
  theme(axis.text.y= element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "bottom", 
        legend.title = element_blank(),
        strip.text.y.left = element_text(angle = 0),
        strip.background = element_rect(fill = "white"),
        strip.text = element_text(colour = 'navy', face = "bold"),
        text = element_text(family = "Roboto Condensed"),
        plot.title = element_text(colour = 'navy', face = "bold")) +
  labs(x = "",
       y = "Estimate",
       title = "Placebo treatment on LAPOP 2013\n(October 2, 2013)")

ggsave(fig_sfa4, file = "figures/suppfig-a4-lapop13.png", width = 3, height = 2,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)


lapop13_list <- list(
  "Naive" = mod_farc_lapop13_1,
  "Dem" = mod_farc_lapop13_2,
  "Dem + Conf" = mod_farc_lapop13_3
)

modelsummary::modelsummary(lapop13_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map_lapop13,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Negotiated-end (FARC)" = 3)) %>%
  kableExtra::row_spec(1,bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(2,bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-a12-lapop13.png",
                         zoom = 1.8,
                         density = 600)

## -----------------------------------------------------------------
## STA13. Most-important problem -----------------------------------
## -----------------------------------------------------------------

problem_df <- table(survey_df$d, survey_df$problem) %>% 
  prop.table(margin = 1) %>% t() %>%
  data.frame(.) %>% tidyr::pivot_wider(., names_from = "Var2", values_from = "Freq") %>% 
  dplyr::rename("Problem" = "Var1", "Pre" = "0", "Post" = "1") %>%
  dplyr::mutate(Difference = round(Post - Pre, 4)*100,
                Pre = paste0(round(Pre*100,2), "%"),
                Post = paste0(round(Post*100,2), "%")) %>%
  dplyr::arrange(desc(Difference)) %>%
  dplyr::mutate(Difference = dplyr::case_when(Difference >= -0.001 ~ paste0("<b style='color:#8fce00'>", round(Difference,2),"\\% ↑</b>"),
                                              T ~ paste0("<b style='color:#ff0000'>", round(Difference,2),"\\% ↓</b>")))

problem_df %>% 
  gt::gt() %>%
  gtExtras::gt_theme_nytimes() %>%
  gt::fmt_markdown(columns = c("Difference")) %>%
  gt::tab_style(
    style = list(cell_text(color = "#000", align = "center",v_align = "middle", weight = "bold")),
    locations = cells_column_labels(columns = c(everything())
    )) %>%
  gt::cols_align(
    align = c("center"),
    columns = c("Pre", "Post", "Difference")
  ) %>%
  gt::tab_options(row_group.font.size = 13,
                  row_group.font.weight = "bold") %>%
  gt::tab_style(
    style = list(
      cell_text(weight = "bold", color = "darkblue")
    ),
    locations = cells_body(rows = 1)
  ) %>%
  gt::gtsave("figures/supp-table-a13-mip.png")

## -----------------------------------------------------------------
## STA14. Only treated regions ------------------------------------
## -----------------------------------------------------------------

regions_list <- list(
  "Naive" = estimatr::lm_robust(scaled_support_agreement ~ d , data = survey_df[survey_df$reg_treat == 1,]),
  "Dem" = estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$reg_treat == 1,]),
  "Dem + Conf"= estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$reg_treat == 1,]),
  "Naive" = estimatr::lm_robust(neg_farc ~ d , data = survey_df[survey_df$reg_treat == 1,]),
  "Dem" = estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$reg_treat == 1,]),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$reg_treat == 1,]),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ d, data = survey_df[survey_df$reg_treat == 1,]),
  "Dem" =  estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$reg_treat == 1,]),
  "Dem + Conf" = estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$reg_treat == 1,])
)

modelsummary::modelsummary(regions_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Signed agreement" = 3, "Negotiated-end (FARC)" = 3, "Concessions (Composite)" = 3)) %>%
  kableExtra::row_spec(1,bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(2,bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-a14-regions.png",
                         zoom = 1.8,
                         density = 600)

## -----------------------------------------------------------------
## ST15. Exclude conflict regions ---------------------------------
## -----------------------------------------------------------------

no_conflict_list <- list(
  "Naive" = estimatr::lm_robust(scaled_support_agreement ~ d , data = survey_df[survey_df$conflict_zone == 0,]),
  "Dem" = estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$conflict_zone == 0,]),
  "Dem + Conf"= estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$conflict_zone == 0,]),
  "Naive" = estimatr::lm_robust(neg_farc ~ d , data = survey_df[survey_df$conflict_zone == 0,]),
  "Dem" = estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$conflict_zone == 0,]),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$conflict_zone == 0,]),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ d, data = survey_df[survey_df$conflict_zone == 0,]),
  "Dem" =  estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df[survey_df$conflict_zone == 0,]),
  "Dem + Conf" = estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df[survey_df$conflict_zone == 0,])
)

modelsummary::modelsummary(no_conflict_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Signed agreement" = 3, "Negotiated-end (FARC)" = 3, "Concessions (Composite)" = 3)) %>%
  kableExtra::row_spec(1,bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(2,bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-a15-no-conflict-zone.png",
                         zoom = 1.8,
                         density = 600)

## -----------------------------------------------------------------
## SFA5. Leave-one-region-out analysis ----------------------------
## -----------------------------------------------------------------

regions <- unique(survey_df$prov_label)

loo_df <- dplyr::bind_rows(run_loo_regression(as.formula(scaled_support_agreement ~ d), regions, survey_df),
                            run_loo_regression(as.formula(neg_farc ~ d), regions, survey_df),
                            run_loo_regression(as.formula(conce_agg_scale ~ d), regions, survey_df)) %>%
  dplyr::mutate(model = factor(dplyr::case_when(outcome == "scaled_support_agreement" ~ "Support for signed\npeace agreement",
                                                outcome == "neg_farc" ~ "Negotiated-end\n(FARC)",
                                                outcome == "conce_agg_scale" ~ "FARC concessions\n(Composite scaled)"),
                               levels =  c("Support for signed\npeace agreement", "Negotiated-end\n(FARC)", "FARC concessions\n(Composite scaled)")),
                id = paste0(id,"(-)"))

fig_sfa5 <- ggplot(loo_df, aes(x = id, y = estimate)) +
  geom_point(size = 2.5) +
  geom_segment(aes(x = id, xend = id, y = conf.low, yend = conf.high), size = 0.5) +
  geom_hline(yintercept = 0, linetype = "longdash", color = "gray60") +
  facet_wrap(~model, labeller = label_value) +
  coord_flip() +
  theme_bw() +
  scale_y_continuous(limits = c(-.15,.38))  +
  theme(#axis.text.y= element_blank(),
    axis.ticks.y = element_blank(),
    legend.position = "bottom", 
    legend.title = element_blank(),
    strip.text.y.left = element_text(angle = 0),
    strip.background = element_rect(fill = "white"),
    strip.text = element_text(colour = 'navy', face = "bold"),
    text = element_text(family = "Roboto Condensed",
                        size = 14)) +
  labs(x = "",
       y = "Estimate")

ggsave(fig_sfa5, file = "figures/suppfig-a5-leave-one-out.png", width = 4, height = 4,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)




## -----------------------------------------------------------------
## STB1. Regression output -----------------------------------------
## -----------------------------------------------------------------

main_models_list <- list(
  "Naive" = estimatr::lm_robust(scaled_support_agreement ~ d , data = survey_df),
  "Dem" = estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(scaled_support_agreement ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df),
  "Naive" = estimatr::lm_robust(neg_farc ~ d , data = survey_df),
  "Dem" = estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf"= estimatr::lm_robust(neg_farc ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df),
  "Naive" = estimatr::lm_robust(conce_agg_scale ~ d, data = survey_df),
  "Dem" =  estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf" = estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df)
)

modelsummary::modelsummary(main_models_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Signed agreement" = 3, "Negotiated-end (FARC)" = 3, "Concessions (Composite)" = 3)) %>%
  kableExtra::row_spec(1,bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(2,bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-b1-main-models.png",
                         zoom = 1.8,
                         density = 600)

## -----------------------------------------------------------------
## SFB1. Belief in FARC upholding agreement ------------------------
## -----------------------------------------------------------------

# Support agreement (FARC) --
summary(mod_farc_demobilize_1 <- estimatr::lm_robust(farc_demobilize ~ d , data = survey_df))
summary(mod_farc_demobilize_2 <- estimatr::lm_robust(farc_demobilize ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df))
summary(mod_farc_demobilize_3 <- estimatr::lm_robust(farc_demobilize ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df))

## Negotiated-end (FARC) --
summary(mod_farc_stop_drug_traffic_1 <- estimatr::lm_robust(farc_stop_drug_traffic ~ d , data = survey_df))
summary(mod_farc_stop_drug_traffic_2 <- estimatr::lm_robust(farc_stop_drug_traffic ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df))
summary(mod_farc_stop_drug_traffic_3 <- estimatr::lm_robust(farc_stop_drug_traffic ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df))

fig_b1_df <- dplyr::bind_rows(
  mod_farc_demobilize_1 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Naive", model = "FARC members to\ndemobilize"),
  mod_farc_demobilize_2 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Demographic", model = "FARC members to\ndemobilize"),
  mod_farc_demobilize_3 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Demographic + Conflict", model = "FARC members to\ndemobilize"),
  mod_farc_stop_drug_traffic_1 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Naive", model = "FARC members to\nstop drugtrafficking"),
  mod_farc_stop_drug_traffic_2 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Demographic", model = "FARC members to\nstop drugtrafficking"),
  mod_farc_stop_drug_traffic_3 %>% broom::tidy(conf.int = T) %>% dplyr::mutate(type = "Demographic + Conflict", model = "FARC members to\nstop drugtrafficking")
) %>% dplyr::filter(term == "d") %>%
  dplyr::mutate(model = forcats::fct_relevel(model, c("FARC members to\ndemobilize", "FARC members to\nstop drugtrafficking")),
                type = forcats::fct_relevel(type, c("Demographic + Conflict", "Demographic", "Naive")))

suppfig_b1 <- ggplot(fig_b1_df, aes(x = type, y = estimate, color = type, shape = type, fill = type)) +
  geom_point(size = 2.5) +
  geom_segment(aes(x = type, xend = type, y = conf.low, yend = conf.high), size = 0.5) +
  geom_hline(yintercept = 0, linetype = "longdash", color = "gray60") +
  facet_wrap(~model, ncol=2, labeller = label_value) +
  coord_flip() +
  theme_bw() +
  scale_y_continuous(limits = c(-.35,.35)) +
  scale_color_manual(guide = guide_legend(reverse = TRUE),
                     values = c("#000000", "darkgray", "#0065b8")) +
  scale_fill_manual(guide = guide_legend(reverse = TRUE),
                    values = c("#000000", "darkgray", "#0065b8")) +
  scale_shape_manual(values = c(21, 22, 23),
                     guide = guide_legend(reverse = TRUE)) +
  theme(axis.text.y= element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "bottom", 
        legend.title = element_blank(),
        strip.text.y.left = element_text(angle = 0),
        strip.background = element_rect(fill = "white"),
        strip.text = element_text(colour = 'navy', face = "bold"),
        text = element_text(family = "Roboto Condensed",
                            size = 14)) +
  labs(x = "",
       y = "Estimate")

ggsave(suppfig_b1, file = "figures/supp-fig-b1-belief-in-farc-upholding.png", width = 2.7, height = 1.5,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)


## -----------------------------------------------------------------
## SFC1. Models individual concessions with FARC ---------------
## -----------------------------------------------------------------

# individual concessions (scaled) ---

# individual concession items --
ivs_concessions <- c("scaled_colconce4", "scaled_colpact11", "scaled_colpact11a",
                     "scaled_colpact1", "scaled_colpact14")
# covars --
covars_naive <- "d"
covars_demo <- "d + age + female + edu + urban + estrato + votesantos"
covars_demo_conf <- "d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone"

naive_cons <- model_concessions(ivs_concessions, covars_naive, survey_df, type = "Naive") %>% dplyr::bind_rows()
demo_cons <- model_concessions(ivs_concessions, covars_demo, survey_df, type = "Demographic") %>% dplyr::bind_rows()
demo_conf_cons <- model_concessions(ivs_concessions, covars_demo_conf, survey_df, type = "Demographic + Conflict") %>% dplyr::bind_rows()

ind_concession_plot_df <- dplyr::bind_rows(naive_cons, demo_cons, demo_conf_cons)

fig_c1 <- ind_concession_plot_df %>% 
  dplyr::mutate(type = forcats::fct_relevel(type, c("Demographic + Conflict", "Demographic", "Naive")),
                term = dplyr::case_when(term == "d" ~ "Exposure\nto Peace\nPlebiscite (D)")) %>%
  ggplot(., aes(x = type, y = estimate, color = type, shape = type, fill = type)) +
  geom_point(size = 2) +
  geom_segment(aes(x = type, xend = type, y = conf.low, yend = conf.high), size = 0.5) +
  geom_hline(yintercept = 0, linetype = "longdash", color = "gray60") +
  facet_grid(term~model_color, switch = "y") +
  coord_flip() +
  theme_bw() +
  scale_y_continuous(limits = c(-.45,.45),
                     breaks = c(-.3,0,.3)) +
  scale_color_manual(guide = guide_legend(reverse = T),
                     values = c("#000000", "darkgray", "#0065b8")) +
  scale_fill_manual(guide = guide_legend(reverse = T),
                    values = c("#000000", "darkgray", "#0065b8")) +
  scale_shape_manual(values = c(21, 22, 23),
                     guide = guide_legend(reverse = T)) +
  theme(axis.text.y= element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "bottom", 
        legend.title = element_blank(),
        strip.text.y.left = element_text(angle = 0),
        strip.background = element_rect(fill = "white"),
        strip.text = ggtext::element_markdown(colour = 'navy', face = "bold"),
        text = element_text(family = "Roboto Condensed")) +
  labs(x = "",
       y = "Estimate")

ggsave(fig_c1, file = "figures/fig-c1-concession-models.png", width = 4, height = 1.5,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)

## -----------------------------------------------------------------
## SFC2. Models individual non-FARC provisions ---------------------
## -----------------------------------------------------------------

# individual provisions (scaled) ---

# individual provision items --
ivs_provisions <- c("scaled_colpact8", "scaled_colpact9", "scaled_colpact10",
                     "scaled_colpact12", "scaled_colpact13")
# covars --
covars_naive <- "d"
covars_demo <- "d + age + female + edu + urban + estrato + votesantos"
covars_demo_conf <- "d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone"

naive_provs <- model_concessions(ivs_provisions, covars_naive, survey_df, type = "Naive") %>% dplyr::bind_rows()
demo_provs <- model_concessions(ivs_provisions, covars_demo, survey_df, type = "Demographic") %>% dplyr::bind_rows()
demo_conf_provs <- model_concessions(ivs_provisions, covars_demo_conf, survey_df, type = "Demographic + Conflict") %>% dplyr::bind_rows()

ind_provisions_plot_df <- dplyr::bind_rows(naive_provs, demo_provs, demo_conf_provs)

fig_c2 <- ind_provisions_plot_df %>% 
  dplyr::mutate(type = forcats::fct_relevel(type, c("Demographic + Conflict", "Demographic", "Naive")),
                term = dplyr::case_when(term == "d" ~ "Exposure\nto Peace\nPlebiscite (D)")) %>%
  ggplot(., aes(x = type, y = estimate, color = type, shape = type, fill = type)) +
  geom_point(size = 2) +
  geom_segment(aes(x = type, xend = type, y = conf.low, yend = conf.high), size = 0.5) +
  geom_hline(yintercept = 0, linetype = "longdash", color = "gray60") +
  facet_grid(term~model, switch = "y") +
  coord_flip() +
  theme_bw() +
  scale_y_continuous(limits = c(-.45,.45),
                     breaks = c(-.3,0,.3)) +
  scale_color_manual(guide = guide_legend(reverse = T),
                     values = c("#000000", "darkgray", "#0065b8")) +
  scale_fill_manual(guide = guide_legend(reverse = T),
                    values = c("#000000", "darkgray", "#0065b8")) +
  scale_shape_manual(values = c(21, 22, 23),
                     guide = guide_legend(reverse = T)) +
  theme(axis.text.y= element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "bottom", 
        legend.title = element_blank(),
        strip.text.y.left = element_text(angle = 0),
        strip.background = element_rect(fill = "white"),
        strip.text = ggtext::element_markdown(colour = 'navy', face = "bold"),
        text = element_text(family = "Roboto Condensed")) +
  labs(x = "",
       y = "Estimate")

ggsave(fig_c2, file = "figures/fig-c2-provisions-models.png", width = 4, height = 1.5,limitsize = FALSE, units = "cm", dpi = 300, scale = 5)


## -----------------------------------------------------------------
## STC2. Latent concessions ---- ------------------------------------
## -----------------------------------------------------------------

latent_concessions_list <- list(
  "Naive" = estimatr::lm_robust(concession_latent ~ d, data = survey_df),
  "Dem" =  estimatr::lm_robust(conce_agg_scale ~ d + age + female + edu + urban + estrato + votesantos, data = survey_df),
  "Dem + Conf" = estimatr::lm_robust(concession_latent ~ d + age + female + edu + urban + estrato + votesantos + victim_ruv + relative_farc_vict + conflict_zone, data = survey_df)
)

modelsummary::modelsummary(latent_concessions_list, 
                           statistic = "conf.int",
                           gof_omit="AIC|BIC|R2",
                           coef_map = covariate_map,
                           fmt = 2) %>%
  kableExtra::add_header_above(c(" " = 1, "Concessions (Latent)" = 3)) %>%
  kableExtra::row_spec(1,bold=T,hline_after = T, color = "darkblue") %>%
  kableExtra::row_spec(2,bold=F,hline_after = T, color = "darkblue") %>%
  kableExtra::save_kable(file = "figures/supp-table-c2-concessions-latent.png",
                         zoom = 1.8,
                         density = 600)
  
